package com.pig4cloud.pigx.system.schedule;

import com.pig4cloud.pigx.common.customize.redis.constants.CommonRedisConstants;
import com.pig4cloud.pigx.system.constant.RedisHashKeyConstant;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 */
@Component
@EnableScheduling
@AllArgsConstructor
public class SymbolOpenPriceTask {

	private final RedisTemplate redis;

	/**
	 * 每日8点设定币对开盘价
	 */
	@Scheduled(cron = "0 0 8 * * ?")
	public void task() {
		Set<String> keys = redis.opsForHash().keys(RedisHashKeyConstant.SYMBOL_LIST);
		for (String key : keys) {
			Object lastPrice = redis.opsForValue().get(CommonRedisConstants.LAST_PRICE + key);
			if (lastPrice != null) {
				redis.opsForValue().set(CommonRedisConstants.OPEN_PRICE + key,lastPrice);
			}
		}
	}

}
